<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>杭州到连云港赣榆区自驾游路线规划</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <style>
        body, html {
            margin: 0;
            padding: 0;
            font-family: "Microsoft YaHei", sans-serif;
            height: 100%;
        }
        .container {
            display: flex;
            height: 100%;
        }
        .sidebar {
            width: 300px;
            height: 100%;
            overflow-y: auto;
            padding: 20px;
            box-sizing: border-box;
            background-color: #f8f9fa;
        }
        #map-container {
            flex: 1;
            height: 100%;
        }
        .day-card {
            background-color: white;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 15px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        .day-title {
            font-weight: bold;
            color: #0078ff;
            margin-bottom: 10px;
            border-bottom: 1px solid #eee;
            padding-bottom: 5px;
        }
        .poi-item {
            margin-bottom: 8px;
            cursor: pointer;
        }
        .poi-item:hover {
            color: #0078ff;
        }
        .category {
            font-weight: bold;
            margin: 10px 0 5px;
        }
        .info-window {
            padding: 10px;
            max-width: 300px;
        }
        .info-title {
            font-weight: bold;
            margin-bottom: 5px;
            color: #0078ff;
        }
        .info-address {
            font-size: 12px;
            color: #666;
            margin-bottom: 5px;
        }
        .info-desc {
            font-size: 13px;
        }
        .btn {
            display: inline-block;
            padding: 5px 10px;
            background: #0078ff;
            color: white;
            border-radius: 4px;
            text-decoration: none;
            font-size: 12px;
            margin-top: 5px;
        }
        .legend {
            position: absolute;
            bottom: 20px;
            right: 20px;
            background: white;
            padding: 10px;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
            z-index: 100;
        }
        .legend-item {
            display: flex;
            align-items: center;
            margin-bottom: 5px;
        }
        .legend-color {
            width: 16px;
            height: 16px;
            margin-right: 8px;
            border-radius: 50%;
        }
        .route-btn {
            margin-top: 15px;
            background: #0078ff;
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="sidebar">
            <h2>杭州到连云港赣榆区自驾游</h2>
            <p>2025年7月12日-2025年7月20日（9天）</p>
            
            <div style="margin-bottom: 15px;">
                <a href="index.html" style="color: #0078ff; text-decoration: none; margin-right: 10px;">首页</a>
                <a href="景点详情.html" style="color: #0078ff; text-decoration: none; margin-right: 10px;">景点详情</a>
                <a href="美食推荐.html" style="color: #0078ff; text-decoration: none;">美食推荐</a>
            </div>
            
            <button class="route-btn" onclick="showFullRoute()">显示完整自驾路线</button>
            
            <div id="itinerary">
                <!-- 行程内容将通过JavaScript动态生成 -->
            </div>
        </div>
        
        <div id="map-container"></div>
        
        <div class="legend">
            <div class="legend-item">
                <div class="legend-color" style="background-color: #3366FF;"></div>
                <span>景点</span>
            </div>
            <div class="legend-item">
                <div class="legend-color" style="background-color: #FF6600;"></div>
                <span>餐厅</span>
            </div>
            <div class="legend-item">
                <div class="legend-color" style="background-color: #33CC33;"></div>
                <span>住宿</span>
            </div>
            <div class="legend-item">
                <div class="legend-color" style="background-color: #0078ff;"></div>
                <span>路线</span>
            </div>
        </div>
    </div>

    <script src="https://webapi.amap.com/maps?v=2.0&key=e5bc63e7a6557bf958ae787e3522b3bc"></script>
    <script>
        // 初始化地图
        const map = new AMap.Map('map-container', {
            zoom: 8,
            center: [120.16, 30.26] // 杭州中心点
        });
        
        // 添加比例尺和指南针控件
        map.addControl(new AMap.Scale());
        map.addControl(new AMap.ToolBar());
        
        // 定义城市坐标
        const cities = {
            '杭州': [120.16, 30.26],
            '宁波': [121.55, 29.88],
            '嘉兴': [120.76, 30.75],
            '苏州': [120.59, 31.30],
            '南通': [120.86, 32.01],
            '盐城': [120.16, 33.35],
            '连云港赣榆区': [119.17, 34.84]
        };
        
        // 定义景点、餐厅和住宿信息
        const pois = [
            // 第1天
            { name: '四明山国家森林公园', type: 'attraction', city: '宁波', position: [121.71, 29.72], day: 1, desc: '茂密森林，清新空气，避暑胜地' },
            { name: '宁波市区酒店', type: 'hotel', city: '宁波', position: [121.55, 29.88], day: 1, desc: '住宿推荐' },
            { name: '宁波汤圆店', type: 'restaurant', city: '宁波', position: [121.54, 29.87], day: 1, desc: '特色美食：宁波汤圆' },
            { name: '海鲜餐厅', type: 'restaurant', city: '宁波', position: [121.56, 29.89], day: 1, desc: '特色美食：新鲜海鲜' },
            
            // 第2天
            { name: '东钱湖', type: 'attraction', city: '宁波', position: [121.87, 29.80], day: 2, desc: '浙江省最大的淡水湖，风景秀丽' },
            { name: '宁波海鲜餐厅', type: 'restaurant', city: '宁波', position: [121.86, 29.79], day: 2, desc: '特色美食：宁波特色海鲜' },
            { name: '嘉兴酒店', type: 'hotel', city: '嘉兴', position: [120.76, 30.75], day: 2, desc: '住宿推荐' },
            { name: '嘉兴粽子店', type: 'restaurant', city: '嘉兴', position: [120.75, 30.74], day: 2, desc: '特色美食：嘉兴粽子' },
            
            // 第3天
            { name: '嘉兴南湖', type: 'attraction', city: '嘉兴', position: [120.77, 30.76], day: 3, desc: '湖景优美，历史悠久' },
            { name: '嘉兴本地菜馆', type: 'restaurant', city: '嘉兴', position: [120.76, 30.74], day: 3, desc: '特色美食：嘉兴本地特色菜' },
            { name: '太湖风景区', type: 'attraction', city: '苏州', position: [120.43, 31.18], day: 3, desc: '中国第三大淡水湖，湖光山色' },
            { name: '苏州酒店', type: 'hotel', city: '苏州', position: [120.59, 31.30], day: 3, desc: '住宿推荐' },
            { name: '松鼠桂鱼餐厅', type: 'restaurant', city: '苏州', position: [120.58, 31.29], day: 3, desc: '特色美食：苏州松鼠桂鱼' },
            
            // 第4天
            { name: '环太湖自然风光区', type: 'attraction', city: '苏州', position: [120.40, 31.15], day: 4, desc: '环太湖自然风光，景色宜人' },
            { name: '苏州本地菜馆', type: 'restaurant', city: '苏州', position: [120.58, 31.28], day: 4, desc: '特色美食：苏州本地特色菜' },
            { name: '南通酒店', type: 'hotel', city: '南通', position: [120.86, 32.01], day: 4, desc: '住宿推荐' },
            { name: '崇川汤包店', type: 'restaurant', city: '南通', position: [120.85, 32.00], day: 4, desc: '特色美食：南通崇川汤包' },
            
            // 第5天
            { name: '狼山', type: 'attraction', city: '南通', position: [120.96, 32.08], day: 5, desc: '长江三峡之一，山水相依' },
            { name: '南通海鲜餐厅', type: 'restaurant', city: '南通', position: [120.95, 32.07], day: 5, desc: '特色美食：南通特色海鲜' },
            { name: '盐城国家级珍禽自然保护区', type: 'attraction', city: '盐城', position: [120.20, 33.32], day: 5, desc: '观鸟胜地，生态环境优美' },
            { name: '盐城酒店', type: 'hotel', city: '盐城', position: [120.16, 33.35], day: 5, desc: '住宿推荐' },
            { name: '盐城麻糕店', type: 'restaurant', city: '盐城', position: [120.15, 33.34], day: 5, desc: '特色美食：盐城麻糕' },
            { name: '大纵湖螃蟹馆', type: 'restaurant', city: '盐城', position: [120.17, 33.36], day: 5, desc: '特色美食：大纵湖螃蟹' },
            
            // 第6天
            { name: '东台条子泥湿地公园', type: 'attraction', city: '盐城', position: [120.49, 32.86], day: 6, desc: '原始湿地景观' },
            { name: '盐城海鲜餐厅', type: 'restaurant', city: '盐城', position: [120.48, 32.85], day: 6, desc: '特色美食：盐城特色海鲜' },
            { name: '赣榆区酒店', type: 'hotel', city: '连云港赣榆区', position: [119.17, 34.84], day: 6, desc: '住宿推荐' },
            { name: '赣榆特色餐厅', type: 'restaurant', city: '连云港赣榆区', position: [119.16, 34.83], day: 6, desc: '特色美食：连云港海鲜、赣榆特色菜' },
            
            // 第7天
            { name: '赣榆金沙滩', type: 'attraction', city: '连云港赣榆区', position: [119.24, 34.82], day: 7, desc: '细软沙滩，海水清澈' },
            { name: '海州湾度假区', type: 'attraction', city: '连云港赣榆区', position: [119.29, 34.77], day: 7, desc: '避开人群的海滨度假胜地' },
            { name: '王记海鲜私房菜', type: 'restaurant', city: '连云港赣榆区', position: [119.25, 34.81], day: 7, desc: '特色美食：新鲜海鲜' },
            { name: '渔歌海鲜私房菜', type: 'restaurant', city: '连云港赣榆区', position: [119.28, 34.79], day: 7, desc: '特色美食：新鲜海鲜' },
            
            // 第8天
            { name: '徐福泊船山风景区', type: 'attraction', city: '连云港赣榆区', position: [119.13, 34.87], day: 8, desc: '历史与自然景观结合' },
            { name: '潘氏风味餐厅', type: 'restaurant', city: '连云港赣榆区', position: [119.12, 34.86], day: 8, desc: '特色美食：潘氏风味' },
            { name: '和安湖湿地公园', type: 'attraction', city: '连云港赣榆区', position: [119.20, 34.90], day: 8, desc: '湿地生态系统，鸟类栖息地' },
            { name: '朱雷农家院餐馆', type: 'restaurant', city: '连云港赣榆区', position: [119.19, 34.89], day: 8, desc: '特色美食：农家菜' },
            
            // 第9天
            { name: '秦山岛旅游景区', type: 'attraction', city: '连云港赣榆区', position: [119.33, 34.73], day: 9, desc: '岛屿风光，海天一色' },
            { name: '连云港特色餐厅', type: 'restaurant', city: '连云港赣榆区', position: [119.32, 34.72], day: 9, desc: '特色美食：连云港特色美食' }
        ];
        
        // 定义每天的行程路线
        const routes = [
            { day: 1, from: '杭州', to: '宁波', waypoints: [] },
            { day: 2, from: '宁波', to: '嘉兴', waypoints: [] },
            { day: 3, from: '嘉兴', to: '苏州', waypoints: [] },
            { day: 4, from: '苏州', to: '南通', waypoints: [] },
            { day: 5, from: '南通', to: '盐城', waypoints: [] },
            { day: 6, from: '盐城', to: '连云港赣榆区', waypoints: [] },
            { day: 9, from: '连云港赣榆区', to: '杭州', waypoints: [] }
        ];
        
        // 创建不同类型的标记
        const markers = [];
        const infoWindows = [];
        
        // 为每个POI创建标记
        pois.forEach(poi => {
            let icon;
            switch(poi.type) {
                case 'attraction':
                    icon = '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-1.png';
                    break;
                case 'restaurant':
                    icon = '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-2.png';
                    break;
                case 'hotel':
                    icon = '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-3.png';
                    break;
            }
            
            const marker = new AMap.Marker({
                position: poi.position,
                title: poi.name,
                icon: new AMap.Icon({
                    size: new AMap.Size(25, 34),
                    image: icon,
                    imageSize: new AMap.Size(25, 34)
                }),
                offset: new AMap.Pixel(-13, -34),
                extData: { day: poi.day, type: poi.type }
            });
            
            // 创建信息窗口
            const content = `
                <div class="info-window">
                    <div class="info-title">${poi.name}</div>
                    <div class="info-address">${poi.city}</div>
                    <div class="info-desc">${poi.desc}</div>
                    <a class="btn" href="https://uri.amap.com/marker?position=${poi.position[0]},${poi.position[1]}&name=${poi.name}&src=mypage&coordinate=gaode&callnative=1" target="_blank">导航到这里</a>
                </div>
            `;
            
            const infoWindow = new AMap.InfoWindow({
                content: content,
                offset: new AMap.Pixel(0, -34)
            });
            
            // 点击标记时打开信息窗口
            marker.on('click', () => {
                infoWindow.open(map, marker.getPosition());
            });
            
            markers.push(marker);
            infoWindows.push(infoWindow);
        });
        
        // 将所有标记添加到地图
        map.add(markers);
        
        // 生成侧边栏行程内容
        const itineraryContainer = document.getElementById('itinerary');
        
        // 按天生成行程
        for (let day = 1; day <= 9; day++) {
            const dayPois = pois.filter(poi => poi.day === day);
            
            // 创建每天的行程卡片
            const dayCard = document.createElement('div');
            dayCard.className = 'day-card';
            
            // 添加日期标题
            const dayTitle = document.createElement('div');
            dayTitle.className = 'day-title';
            const date = new Date(2025, 6, 11 + day); // 7月12日开始
            dayTitle.textContent = `第${day}天 (${date.getMonth() + 1}月${date.getDate()}日)`;
            dayCard.appendChild(dayTitle);
            
            // 添加当天行程路线按钮
            const route = routes.find(r => r.day === day);
            if (route) {
                const routeBtn = document.createElement('button');
                routeBtn.className = 'route-btn';
                routeBtn.style.marginBottom = '10px';
                routeBtn.textContent = `显示第${day}天路线: ${route.from} → ${route.to}`;
                routeBtn.onclick = () => showDayRoute(day);
                dayCard.appendChild(routeBtn);
            }
            
            // 分类添加景点
            const attractions = dayPois.filter(poi => poi.type === 'attraction');
            if (attractions.length > 0) {
                const attractionTitle = document.createElement('div');
                attractionTitle.className = 'category';
                attractionTitle.textContent = '景点';
                dayCard.appendChild(attractionTitle);
                
                attractions.forEach(attraction => {
                    const poiItem = document.createElement('div');
                    poiItem.className = 'poi-item';
                    poiItem.textContent = attraction.name;
                    poiItem.onclick = () => {
                        // 定位到该POI并打开信息窗口
                        const index = pois.findIndex(p => p.name === attraction.name && p.day === day);
                        if (index !== -1) {
                            map.setCenter(markers[index].getPosition());
                            map.setZoom(14);
                            infoWindows[index].open(map, markers[index].getPosition());
                        }
                    };
                    dayCard.appendChild(poiItem);
                });
            }
            
            // 分类添加餐厅
            const restaurants = dayPois.filter(poi => poi.type === 'restaurant');
            if (restaurants.length > 0) {
                const restaurantTitle = document.createElement('div');
                restaurantTitle.className = 'category';
                restaurantTitle.textContent = '餐饮';
                dayCard.appendChild(restaurantTitle);
                
                restaurants.forEach(restaurant => {
                    const poiItem = document.createElement('div');
                    poiItem.className = 'poi-item';
                    poiItem.textContent = restaurant.name;
                    poiItem.onclick = () => {
                        // 定位到该POI并打开信息窗口
                        const index = pois.findIndex(p => p.name === restaurant.name && p.day === day);
                        if (index !== -1) {
                            map.setCenter(markers[index].getPosition());
                            map.setZoom(14);
                            infoWindows[index].open(map, markers[index].getPosition());
                        }
                    };
                    dayCard.appendChild(poiItem);
                });
            }
            
            // 分类添加住宿
            const hotels = dayPois.filter(poi => poi.type === 'hotel');
            if (hotels.length > 0) {
                const hotelTitle = document.createElement('div');
                hotelTitle.className = 'category';
                hotelTitle.textContent = '住宿';
                dayCard.appendChild(hotelTitle);
                
                hotels.forEach(hotel => {
                    const poiItem = document.createElement('div');
                    poiItem.className = 'poi-item';
                    poiItem.textContent = hotel.name;
                    poiItem.onclick = () => {
                        // 定位到该POI并打开信息窗口
                        const index = pois.findIndex(p => p.name === hotel.name && p.day === day);
                        if (index !== -1) {
                            map.setCenter(markers[index].getPosition());
                            map.setZoom(14);
                            infoWindows[index].open(map, markers[index].getPosition());
                        }
                    };
                    dayCard.appendChild(poiItem);
                });
            }
            
            itineraryContainer.appendChild(dayCard);
        }
        
        // 当前显示的路线
        let currentRoute = null;
        
        // 显示特定天的路线
        function showDayRoute(day) {
            // 清除当前路线
            if (currentRoute) {
                map.remove(currentRoute);
            }
            
            const route = routes.find(r => r.day === day);
            if (!route) return;
            
            const startPos = cities[route.from];
            const endPos = cities[route.to];
            
            // 使用高德地图驾车路线规划
            AMap.plugin('AMap.Driving', function() {
                const driving = new AMap.Driving({
                    policy: AMap.DrivingPolicy.LEAST_TIME,
                    map: map
                });
                
                driving.search(
                    new AMap.LngLat(startPos[0], startPos[1]), 
                    new AMap.LngLat(endPos[0], endPos[1]),
                    { waypoints: route.waypoints.map(wp => new AMap.LngLat(wp[0], wp[1])) },
                    function(status, result) {
                        if (status === 'complete') {
                            // 保存当前路线
                            currentRoute = driving.getRoute();
                            
                            // 调整地图视野以包含路线
                            map.setFitView();
                        }
                    }
                );
            });
            
            // 过滤出当天的POI并显示
            showDayPOIs(day);
        }
        
        // 显示完整自驾路线
        function showFullRoute() {
            // 清除当前路线
            if (currentRoute) {
                map.remove(currentRoute);
            }
            
            // 显示所有POI
            markers.forEach(marker => marker.show());
            
            // 使用高德地图驾车路线规划
            AMap.plugin('AMap.Driving', function() {
                const driving = new AMap.Driving({
                    policy: AMap.DrivingPolicy.LEAST_TIME,
                    map: map
                });
                
                // 构建完整路线的途经点
                const waypoints = [];
                for (let i = 1; i < Object.keys(cities).length - 1; i++) {
                    const city = Object.keys(cities)[i];
                    waypoints.push(new AMap.LngLat(cities[city][0], cities[city][1]));
                }
                
                const startPos = cities['杭州'];
                const endPos = cities['连云港赣榆区'];
                
                driving.search(
                    new AMap.LngLat(startPos[0], startPos[1]), 
                    new AMap.LngLat(endPos[0], endPos[1]),
                    { waypoints: waypoints },
                    function(status, result) {
                        if (status === 'complete') {
                            // 保存当前路线
                            currentRoute = driving.getRoute();
                            
                            // 调整地图视野以包含路线
                            map.setFitView();
                        }
                    }
                );
            });
        }
        
        // 显示特定天的POI
        function showDayPOIs(day) {
            markers.forEach(marker => {
                if (marker.getExtData().day === day) {
                    marker.show();
                } else {
                    marker.hide();
                }
            });
        }
        
        // 初始显示所有POI
        markers.forEach(marker => marker.show());
        
        // 调整地图视野以包含所有标记
        map.setFitView();
    </script>
</body>
</html> 